/**
 * @(#) CodeEntityInitiationRelation��2007-10-23
 * Copyright 2007 Program Analysis Research Group(PARG),Institute of Software, Peking University.
 * All rights reserved.
 */
package edu.pku.sei.pgie.analyzer.internal.relation;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;

import edu.pku.sei.pgie.analyzer.internal.CodeEntitySymbolTable;
import edu.pku.sei.pgie.analyzer.internal.VisitorWithContext;

/**
 * @author HeLi
 */
public class CodeEntityInitiationRelation extends AbstractCodeEntityRelation {

	public class InitiationVisitor extends VisitorWithContext {
		List<String[]> container;

		public InitiationVisitor() {
			super(true);
			this.container = new ArrayList<String[]>();
		}

		public List<String[]> getResult() {
			return this.container;
		}

		public boolean visit(AnonymousClassDeclaration node) {
			String typeName = peekTypeFQN();
			super.visit(node);
			String anonymousName = peekTypeFQN();
			if (typeName != null && anonymousName != null) {
				container.add(new String[] { typeName, anonymousName });
			}
			return true;
		}

	}

	public String[][] collectCallBack(CompilationUnit root,
			CodeEntitySymbolTable symbolTable) throws Exception {
		InitiationVisitor visitor = new InitiationVisitor();
		root.accept(visitor);
		List<String[]> result = visitor.getResult();
		return result.toArray(new String[result.size()][]);
	}
}
